<template>
  <!--
      作者：luoyiming
      时间：2019-10-25
      描述：会员-用户列表-会员等级
  -->
  <el-dialog title="学生信息" :visible.sync="dialogVisible" @close='dialogFormVisible' :close-on-click-modal="false"
    :close-on-press-escape="false">
    <el-form size="small" :model="forms">
      <el-form-item label="姓名" :label-width="formLabelWidth">
        <el-input v-model="form.username" autocomplete="off"></el-input>
      </el-form-item>
      <el-form-item label="手机号" :label-width="formLabelWidth">
        <el-input v-model="form.mobile" autocomplete="off"></el-input>
      </el-form-item>
      <el-form-item label="所属年级："   :label-width="formLabelWidth" >
        <el-select  v-model="form.nianji_id">
          <template v-for="cat in categoryList">
            <el-option :value="cat.category_id" :key="cat.category_id" :label="cat.name"></el-option>
            <template v-if="cat.child !== undefined" v-for="two in cat.child">
              <el-option :value="two.category_id" :key="two.category_id" :label="two.name" style="padding-left: 30px;">
              </el-option>
              <template v-if="two.child !== undefined" v-for="three in two.child">
                <el-option :value="three.category_id" :key="three.category_id" :label="three.name"
                  style="padding-left: 60px;"></el-option>
              </template>
            </template>
          </template>
        </el-select>
      </el-form-item>


      <el-form-item label="班主任" :label-width="formLabelWidth">
        <el-input v-model="form.banzhuren" autocomplete="off"></el-input>
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button @click="dialogFormVisible">取 消</el-button>
      <el-button type="primary" @click="editUser" :loading="loading">确 定</el-button>
    </div>
  </el-dialog>
</template>

<script>
  import UserApi from '@/api/user.js';
  export default {
    data() {
      return {
        /*左边长度*/
        formLabelWidth: '120px',
        /*是否显示*/
        loading: false,
        dialogVisible: false,
        nianji_id:'',
        form:{
          nianji_id:'',
          banji_id:'',
          username:'',
          banzhuren:'',
          mobile:''
        },
      };
    },
    props: ['open_edit', 'form', 'categoryList'],
    created() {

      this.dialogVisible = this.open_edit;

    },

    methods: {

      /*修改用户*/
      editUser() {
        let self = this;
        self.loading = true;
        let params = self.form;
        UserApi.edituser(params, true)
          .then(data => {
            self.loading = false;
            if (data.code == 1) {
              self.$message({
                message: '恭喜你，用户修改成功',
                type: 'success'
              });
              self.dialogFormVisible(true);
            }
          })
          .catch(error => {
            self.loading = false;
          });
      },

      /*关闭弹窗*/
      dialogFormVisible(e) {
        if (e) {
          this.$emit('closeDialog', {
            type: 'success',
            openDialog: false
          })
        } else {
          this.$emit('closeDialog', {
            type: 'error',
            openDialog: false
          })
        }
      }

    }
  };
</script>

<style></style>
